﻿using System;

namespace NumericalSolution {
  abstract class Diffusion1D {
    protected int p_numberOfNodes;
    protected double p_deltaX;
    protected double p_deltaTime;
    protected double p_endTime;
    protected double p_currentTime = 0.0;
    protected double[] p_current_u;
    protected double[] p_previous_u;
    protected double p_alpha = 1.0;

    public double Alpha {
      get { return p_alpha; }
      set { p_alpha = value; }
    }

    public int NumberOfNodes {
      get { return p_numberOfNodes; }
      set {
        p_numberOfNodes = value;
        p_deltaX = 1.0 / (p_numberOfNodes - 1);
      }
    }
    public double DeltaX {
      get { return p_deltaX; }
    }

    public double DeltaTime {
      get { return p_deltaTime; }
      set { p_deltaTime = value; }
    }

    public double CurrentTime {
      get { return p_currentTime; }
      set { p_currentTime = value; }
    }

    public double EndTime {
      get { return p_endTime; }
      set { p_endTime = value; }
    }

    public double[] Initialize() {
      p_current_u = new double[p_numberOfNodes];
      p_previous_u = new double[p_numberOfNodes];

      p_current_u[0] = 0.0;
      for (int i = 1; i < p_numberOfNodes - 1; i++) {
        p_current_u[i] = Math.Sin(Math.PI * i * p_deltaX);
      }
      p_current_u[p_numberOfNodes - 1] = 0.0;

      return p_current_u;
    }

    public abstract double[] Next();

    protected void Age() {
      for (int i = 0; i < p_numberOfNodes; i++) {
        p_previous_u[i] = p_current_u[i];
      }
    }

  }
}
